//
//  TrainingGoalModel.swift
//  DaRings
//
//  Created by HFY on 2022/11/30.
//

import UIKit
import MYModule

open class TrainingGoalModel: NSObject {
    
    public let contentType: TrainingTypeContent
    
    public let title: String?
    
    public let items: [TrainingGoalItemModel]
    
    public init(contentType: TrainingTypeContent, selectedTintColor: UIColor?) {
        
        self.contentType = contentType
        self.title = contentType.title
        let unit = contentType.targetUnit ?? ""
        
        self.items = contentType.targets(type: Unit.sharedInstance.myType).map {
            let item = TrainingGoalItemModel(contentType: contentType, target: $0, unit: unit)
            return item
        }
        
        for i in 0..<items.count {
            if i == 1 {
                let item = items[1]
                item.isSelected = true
            }
        }
        
        items.enumerated().forEach {
            let desc = contentType.targetDescs?[$0]
            $1.desc = desc
            $1.selectedTintColor = selectedTintColor
        }
        
        
        super.init()
        
    }
    
}

extension TrainingGoalModel {
    
    public var selectedItem: TrainingGoalItemModel? {
        
        return items.filter({ $0.isSelected == true }).first
        
    }
    
}


